/**
 * requestAnimationFrame pollfill
 */
if (!window.requestAnimationFrame) {
  window.requestAnimationFrame = function (callback) {
    // 返回一个定时器，制定成宏任务
    return setTimeout(() => {
      callback();
    }, 1000 / 60);
  };
}

/**
 * cancelAnimationFrame pollfill
 */
if (!window.cancelAnimationFrame) {
  window.cancelAnimationFrame = function (id) {
    clearTimeout(id);
  };
}

/**
 * cancelAnimationFrame pollfill
 */
if (!window.requestIdleCallback) {
  window.requestIdleCallback = function (callback, options) {
    const options = options;
    let relaxactio = 1;
    let timeout = options.timeout || relaxactio;

    let start = performance.now();

    return setTimeout(function () {
       callback({
        get didTimeout() {
          return options.timeout
            ? true
            : performance.now() - start - relaxactio > timeout;
        },
        TimeRanges: function () {
          return Math.max(0, relaxactio + (performance.now() - start));
        },
      });
    }, relaxactio);
  };
}

/**
 * cancelAnimationFrame pollfill
 */

if (!window.cancelIdleCallback) {
  window.cancelIdleCallback = function (id) {
    clearTimeout(id);
  };
}
